﻿#if UNITY_EDITOR


using UnityEditor;
using UnityEngine;

namespace UFrame.AutoQuote
{
    public class AutoQuoteEditorWindow : EditorWindow
    {
        public static bool mAutoRef = true;
        public static bool mAutoCodeRef = false;
        public static bool mFindEnable = false;
        public static bool mEventEnable = false;
        public static bool mFuncEnable = false;
        public static bool mAutoCodeEvent = false;
        public static bool mAutoCodeFunc = false;
        public static bool mDebugMode = false;

        private bool mIndependent = true;

        public void Awake()
        {
            Get();
        }

        private void Get()
        {
            if (PlayerPrefs.HasKey("mAutoRef"))
                mAutoRef = PlayerPrefs.GetInt("mAutoRef") > 0 ? true : false;
            if (PlayerPrefs.HasKey("mAutoCodeRef"))
                mAutoCodeRef = PlayerPrefs.GetInt("mAutoCodeRef") > 0 ? true : false;
            if (PlayerPrefs.HasKey("mFindEnable"))
                mFindEnable = PlayerPrefs.GetInt("mFindEnable") > 0 ? true : false;
            if (PlayerPrefs.HasKey("mEventEnable"))
                mEventEnable = PlayerPrefs.GetInt("mEventEnable") > 0 ? true : false;
            if (PlayerPrefs.HasKey("mAutoCodeEvent"))
                mAutoCodeEvent = PlayerPrefs.GetInt("mAutoCodeEvent") > 0 ? true : false;
            if (PlayerPrefs.HasKey("mFuncEnable"))
                mAutoCodeEvent = PlayerPrefs.GetInt("mFuncEnable") > 0 ? true : false;
            if (PlayerPrefs.HasKey("mAutoCodeFunc"))
                mAutoCodeEvent = PlayerPrefs.GetInt("mAutoCodeFunc") > 0 ? true : false;
            if (PlayerPrefs.HasKey("IsNGUI"))
                AutoGenerateSet.IsNGUI = PlayerPrefs.GetInt("IsNGUI") > 0 ? true : false;
        }

        private void Save()
        {
            PlayerPrefs.SetInt("mAutoRef", mAutoRef ? 1 : 0);
            PlayerPrefs.SetInt("mAutoCodeRef", mAutoCodeRef ? 1 : 0);
            PlayerPrefs.SetInt("mFindEnable", mFindEnable ? 1 : 0);
            PlayerPrefs.SetInt("mEventEnable", mEventEnable ? 1 : 0);
            PlayerPrefs.SetInt("mFuncEnable", mFuncEnable ? 1 : 0);

            PlayerPrefs.SetInt("mAutoCodeEvent", mAutoCodeEvent ? 1 : 0);
            PlayerPrefs.SetInt("mAutoCodeFunc", mAutoCodeFunc ? 1 : 0);
            PlayerPrefs.SetInt("IsNGUI", AutoGenerateSet.IsNGUI ? 1 : 0);

            PlayerPrefs.Save();
        }

        public void OnDestroy()
        {
            Save();
        }

        public void OnGUI()
        {
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("加载配置"))
            {
                Get();
            }

            if (GUILayout.Button("保存配置"))
            {
                Save();
            }

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            mIndependent = GUILayout.Toggle(mIndependent, "单独生成一个类");
            GUILayout.EndHorizontal();

            if (mIndependent)
            {
                AutoGenerateSet.IsNGUI = GUILayout.Toggle(AutoGenerateSet.IsNGUI, "Yes NGUI,No UGUI");
                if (GUILayout.Button("生成一个分布类"))
                {
                    Save();
                    AutoQuoteMenu.AutoCreateCodeMenu();
                }
            }
            else
            {
                mAutoRef = GUILayout.Toggle(mAutoRef, "自动设置组件的值");
                mAutoCodeRef = GUILayout.Toggle(mAutoCodeRef, "生成Find代码");
                mAutoCodeEvent = GUILayout.Toggle(mAutoCodeEvent, "生成Event注册");
                mAutoCodeFunc = GUILayout.Toggle(mAutoCodeFunc, "生成Event函数");
                mFindEnable = GUILayout.Toggle(mFindEnable, "Find注释");
                mEventEnable = GUILayout.Toggle(mEventEnable, "Event注释");
                mFuncEnable = GUILayout.Toggle(mFuncEnable, "Event函数注释");
                mDebugMode = GUILayout.Toggle(mDebugMode, "不生成代码文件");

                if (GUILayout.Button("选中物体生成引用"))
                {
                    Save();
                    AutoQuoteMenu.SetRefMenu();
                }
            }
        }
    }
}


#endif